/**
 * Created by luyon on 2017/8/23.
 */

"use strict";

import React from "react" ;
import {connect} from "react-redux" ;
import {mapStateToProps, mapDispatchToProps} from "./FilmCommentRedux" ;
import FilmCommentOne from "./FilmCommentOne/FilmCommentOne"
import UrlManager from "../../../../utils/UrlManager" ;
import NetworkEngine from "../../../../utils/NetworkEngine" ;
import xjt from "../../../../static/img/h5/xiala.png";


class FilmCommentContainer extends React.Component {
    constructor(p) {
        super(p);
        this.transmit = this.transmit.bind(this)//回复
        // this.newReplyList = this.newReplyList.bind(this)//回复
        this.getNewCommentList = this.getNewCommentList.bind(this);

    }

    transmit(userId, commentId, nickName) {
        return this.props.getSomeValue(userId, commentId, nickName)
    }

    getNewCommentList() {
        return this.props.newCommentList();
    }

    closeModel() {
        $("#cancel_model").hide();
    }
    showOtherComment(){
        $(this.refs.moreComment).show();
    }
    hideMoreComment(){
        $(this.refs.moreComment).hide();

    }

    cancelAttention() {
        let id = sessionStorage.getItem("deleteId")
        if (sessionStorage.getItem("deleteStatus") === "pinglun") {
            let urlManager = new UrlManager();
            NetworkEngine(
                "get",
                urlManager.deleteComment() + "/" + id,
            ).then(
                data => {
                    if (data.data.status == "0") {
                        this.getNewCommentList();
                    }
                }
            ).catch(
                err => {

                }
            )
        } else if (sessionStorage.getItem("deleteStatus") === "huifu") {
            let urlManager = new UrlManager();
            NetworkEngine(
                "get",
                urlManager.deleteReply() + "/" + id,
            ).then(
                data => {
                    if (data.data.status == "0") {
                        this.getNewCommentList();

                        let btnId = "#id" + id;
                        $(btnId).click()
                    }
                }
            ).catch(
                err => {

                }
            )
        }
        $("#cancel_model").hide();
    }

    render() {

        let data = this.props.filmCommentList;
        let commentList = data.list;
        let data2 = this.props.filmCommentListTwo;
        let rep = this.props.re;

        let commentList2 = data2.list;
        return (
            <div>
                <p className="comments-title">
                    评论
                    <span className="c-num" style={{display: 'none'}}>已有{data.totalCount}条点评</span>
                </p>
                {
                    commentList.map((data, i) => {
                        return <FilmCommentOne
                            key={i}
                            content={data.content}            //评论内容
                            nickName={data.nickName}          //昵称
                            headUrl={data.headUrl}            //头像
                            time={data.time}                  //评论时间
                            id={data.id}                      //id
                            num={data.num}                    //评论数量
                            type={data.type}                  //type
                            status={data.status}                  //认证状态
                            session={sessionStorage.getItem("id")}

                            userId={data.userId}                  //认证状态
                            transmit={this.transmit}
                            getNewCommentList={this.getNewCommentList}
                            replyListData={rep}

                        />
                    })
                }


                <p style={{display:'none'}} ref="moreComment">
                    {
                        commentList2.map((data, i) => {
                            return <FilmCommentOne
                                key={i}
                                content={data.content}            //评论内容
                                nickName={data.nickName}          //昵称
                                headUrl={data.headUrl}            //头像
                                time={data.time}                  //评论时间
                                id={data.id}                      //id
                                num={data.num}                    //评论数量
                                type={data.type}                  //type
                                status={data.status}                  //认证状态
                                session={sessionStorage.getItem("id")}
                                userId={data.userId}                  //认证状态
                                transmit={this.transmit}
                                getNewCommentList={this.getNewCommentList}
                                replyListData={rep}

                            />
                        })
                    }
                </p>
                {
                    data2.totalCount==0?<div></div>:<p className="all-comments" onClick={this.showOtherComment.bind(this)} ref="character">全部评论<img src={xjt} alt="下拉" /></p>
                }
            </div>
        )
    }
}

const FilmComment = connect(mapStateToProps, mapDispatchToProps)(FilmCommentContainer);

export {FilmComment as default} ;